package com.heyue.ems.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.heyue.common.log.annotation.Log;
import com.heyue.common.log.enums.BusinessType;
import com.heyue.common.security.annotation.PreAuthorize;
import com.heyue.ems.domain.Van;
import com.heyue.ems.service.IVanService;
import com.heyue.common.core.web.controller.BaseController;
import com.heyue.common.core.web.domain.AjaxResult;
import com.heyue.common.core.utils.poi.ExcelUtil;
import com.heyue.common.core.web.page.TableDataInfo;

/**
 * 承运车辆（基础）Controller
 * 
 * @author WCHU
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/van")
public class VanController extends BaseController
{
    @Autowired
    private IVanService vanService;

    /**
     * 查询承运车辆（基础）列表
     */
    @PreAuthorize(hasPermi = "ems:van:list")
    @GetMapping("/list")
    public TableDataInfo list(Van van)
    {
        startPage();
        List<Van> list = vanService.selectVanList(van);
        return getDataTable(list);
    }

    /**
     * 导出承运车辆（基础）列表
     */
    @PreAuthorize(hasPermi = "ems:van:export")
    @Log(title = "承运车辆（基础）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Van van) throws IOException
    {
        List<Van> list = vanService.selectVanList(van);
        ExcelUtil<Van> util = new ExcelUtil<Van>(Van.class);
        util.exportExcel(response, list, "承运车辆（基础）数据");
    }

    /**
     * 获取承运车辆（基础）详细信息
     */
    @PreAuthorize(hasPermi = "ems:van:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(vanService.selectVanById(id));
    }

    /**
     * 新增承运车辆（基础）
     */
    @PreAuthorize(hasPermi = "ems:van:add")
    @Log(title = "承运车辆（基础）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Van van)
    {
        return toAjax(vanService.insertVan(van));
    }

    /**
     * 修改承运车辆（基础）
     */
    @PreAuthorize(hasPermi = "ems:van:edit")
    @Log(title = "承运车辆（基础）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Van van)
    {
        return toAjax(vanService.updateVan(van));
    }

    /**
     * 删除承运车辆（基础）
     */
    @PreAuthorize(hasPermi = "ems:van:remove")
    @Log(title = "承运车辆（基础）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vanService.deleteVanByIds(ids));
    }
}
